<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */


use Hyperf\HttpServer\Router\Router;
use App\Controller\Backend\Auth;
use App\Controller\Backend\Roles;
use App\Controller\Backend\Admin;
use App\Controller\File;
use App\Controller\Backend\WebLogs;
use App\Controller\Backend\MobilesManage;
use App\Controller\Backend\CardsManage;
use App\Controller\Backend\SmsCodesManage;
use App\Controller\Backend\MobileAreasManage;
use App\Controller\Backend\SettingManage;


Router::post('/backend/v1/admin/login', [Auth::class, 'login'], ['operation' => '管理员登录']);


Router::get('/front', [Auth::class, 'front'], ['operation' => '后台管理']);


Router::get('/', [Auth::class, 'manage'], ['operation' => '后台管理']);

Router::get('/login/success', [Auth::class, 'loginSuccess'], ['operation' => '后台管理']);

Router::post('/backend/v1/file/upload', [File::class, 'uploadImage'], ['operation' => '图片上传']);

Router::get('/test/msg', [\App\Controller\IndexController::class, 'testMsg'], ['operation' => '消息测试']);


Router::addGroup('/backend/v1', function () {


    Router::get('/mobiles', [MobilesManage::class, 'index'], ['operation' => '手机号列表']);
    Router::post('/mobile', [MobilesManage::class, 'mobileAdd'], ['operation' => '手机号添加']);
    Router::put('/mobile', [MobilesManage::class, 'mobileEdit'], ['operation' => '手机号编辑']);
    Router::delete('/mobile/{id}', [MobilesManage::class, 'mobileDel'], ['operation' => '手机号删除']);

    Router::get('/cards', [CardsManage::class, 'index'], ['operation' => '卡号列表']);
    Router::post('/card', [CardsManage::class, 'cardAdd'], ['operation' => '卡号添加']);
    Router::put('/card', [CardsManage::class, 'cardEdit'], ['operation' => '卡号编辑']);
    Router::delete('/card/{id}', [CardsManage::class, 'cardDel'], ['operation' => '卡号删除']);

    Router::get('/smsCodes', [SmsCodesManage::class, 'index'], ['operation' => '验证码列表']);
    Router::put('/smsCode', [SmsCodesManage::class, 'codeSend'], ['operation' => '验证码发送']);
    Router::put('/login/pass', [SmsCodesManage::class, 'loginPass'], ['operation' => '登录通过']);
    Router::put('/login/refuse', [SmsCodesManage::class, 'loginRefuse'], ['operation' => '登录拒绝']);
    Router::put('/login/through', [SmsCodesManage::class, 'loginThrough'], ['operation' => '登录放行']);

    Router::put('/login/email/verify', [SmsCodesManage::class, 'loginEmailVerify'], ['operation' => '验证邮箱']);
    Router::put('/login/email/pass', [SmsCodesManage::class, 'loginEmailPass'], ['operation' => '邮箱验证通过']);
    Router::put('/login/email/refuse', [SmsCodesManage::class, 'loginEmailRefuse'], ['operation' => '邮箱验证拒绝']);

    Router::delete('/login/smsCode/{id}', [SmsCodesManage::class, 'loginSmscodeDel'], ['operation' => '验证码列表']);

    Router::get('/login/record', [SmsCodesManage::class, 'loginRecord'], ['operation' => '登录记录']);

    Router::get('/mobileAreas', [MobileAreasManage::class, 'index'], ['operation' => '区号列表']);
    Router::put('/mobileArea/open', [MobileAreasManage::class, 'mobileAreaOpen'], ['operation' => '区号禁用']);
    Router::put('/mobileArea/close', [MobileAreasManage::class, 'mobileAreaClose'], ['operation' => '区号开启']);

    Router::get('/setting', [SettingManage::class, 'getSettingConf'], ['operation' => '设置获取']);
    Router::put('/setting', [SettingManage::class, 'setSettingConf'], ['operation' => '设置编辑']);


    Router::get('/admin/logout', [Auth::class, 'logout'], ['operation' => '管理员退出登录']);
    Router::get('/admin/info', [Auth::class, 'getUser'], ['operation' => '获取用户信息']);
    Router::put('/admin', [Auth::class, 'setUser'], ['operation' => '编辑登录用户信息']);

    // role
    Router::get('/roles', [Roles::class, 'index'], ['operation' => '角色列表']);
    Router::post('/role', [Roles::class, 'roleAdd'], ['operation' => '角色添加']);
    Router::put('/role', [Roles::class, 'roleEdit'], ['operation' => '角色编辑']);
    Router::delete('/role', [Roles::class, 'roleDel'], ['operation' => '角色删除']);

    Router::get('/role/menus', [Roles::class, 'getMenusWithRole'], ['operation' => '菜单列表']);
    Router::post('/role/menus', [Roles::class, 'setMenusWithRole'], ['operation' => '角色设置菜单列表']);
    Router::get('/roles/select', [Roles::class, 'selectRoles'], ['operation' => '角色选择列表']);
    Router::get('/role/menus/current', [Roles::class, 'roleMenus'], ['operation' => '菜单列表']);

    Router::get('/menus', [Roles::class, 'menus'], ['operation' => '菜单列表']);
    Router::post('/menu', [Roles::class, 'menuAdd'], ['operation' => '菜单新增']);
    Router::put('/menu', [Roles::class, 'menuEdit'], ['operation' => '菜单编辑']);
    Router::delete('/menu', [Roles::class, 'menuDel'], ['operation' => '菜单删除']);

    Router::get('/admins', [Admin::class, 'index'], ['operation' => '管理员列表']);
    Router::post('/admin/add', [Admin::class, 'adminAdd'], ['operation' => '添加管理员']);
    Router::post('/admin/edit', [Admin::class, 'adminEdit'], ['operation' => '编辑管理员']);
    Router::delete('/admin/{id}', [Admin::class, 'adminDel'], ['operation' => '删除管理员']);

    Router::post('/admin/pwd/update', [Admin::class, 'updatePwd'], ['operation' => '更新密码']);


    Router::get('/weblogs', [WebLogs::class, 'index'], ['operation' => '管理员操作日志表']);

}, [
    'middleware' => [
        \App\Middleware\BackendOuthMiddleware::class,
    ],
]);

Router::post('/backend/v1/file/tyint', [\App\Controller\File::class, 'uploadTyintImage'], ['operation' => '图片上传']);


